<?php
class IkebanaVo extends SzAbstractMySqlVo
{

    private $userId;
    private $type;
    private $combinationIds;
    private $saveTime;

    /**
     * Initialize IkebanaVo.
     *
     * @param $userId
     * @param $type
     * @param $combinationIds
     * @param $saveTime
     * @param boolean $isInsert default false, means for now this vo is initialized not for insert process
     * @return IkebanaVo
     */
    public function __construct($userId, $type, $combinationIds, $saveTime, $isInsert = false) {
        $this->userId = $userId;
        $this->type = $type;
        $this->combinationIds = json_decode($combinationIds, true);
        $this->saveTime = $saveTime;

        $this->isInsert = $isInsert;
        $this->voClassName = 'IkebanaVo';
        $this->ormName = 'Ikebana';
    }

    /**
     * @see SzAbstractVo::toArray
     */
    public function toArray($needEncode = false)
    {
        return array(
            'userId' => $this->getUserId(),
            'type' => $this->getType(),
            'combinationIds' => ($needEncode) ? $this->getCombinationIds() : $this->getRawCombinationIds(),
            'saveTime' => $this->getSaveTime(),
        );
    }

    /**
     * @see SzAbstractVo::toEntireArray
     */
    public function toEntireArray($needEncode = false)
    {
        return array(
            'userId' => $this->getUserId(),
            'type' => $this->getType(),
            'combinationIds' => ($needEncode) ? $this->getCombinationIds() : $this->getRawCombinationIds(),
            'saveTime' => $this->getSaveTime(),
        );
    }

    /**
     * @see SzAbstractVo::toPureArray
     */
    public function toPureArray()
    {
        return array(
            $this->getUserId(),
            $this->getType(),
            $this->getCombinationIds(),
            $this->getSaveTime(),
        );
    }

    public function getUserId()
    {
        return $this->userId;
    }

    public function setUserId($val)
    {
        $this->saveColumnStatus(0, $this->userId);
        $this->userId = $val;
    }

    public function getType()
    {
        return $this->type;
    }

    public function setType($val)
    {
        $this->saveColumnStatus(1, $this->type);
        $this->type = $val;
    }

    public function getCombinationIds()
    {
        return json_encode($this->combinationIds);
    }

    public function getRawCombinationIds()
    {
        return $this->combinationIds;
    }

    public function setCombinationIds($val)
    {
        $encodedLength = SzUtility::strLen(json_encode($val));
        if ($encodedLength > 512) {
            SzLogger::get()->error('[IkebanaVo] The length of column combinationIds exceed the limit, length / limit: ' . $encodedLength . ' / 512');
            throw new SzException(10522, array('IkebanaVo', '512', $encodedLength));
        } else if ($encodedLength > 460) {
            SzLogger::get()->warn('[IkebanaVo] The length of column combinationIds exceed the warning level, length / limit: ' . $encodedLength . ' / 512');
        }
        $this->saveColumnStatus(2, $this->combinationIds);
        $this->combinationIds = $val;
    }

    public function getSaveTime()
    {
        return $this->saveTime;
    }

    public function setSaveTime($val)
    {
        $this->saveColumnStatus(3, $this->saveTime);
        $this->saveTime = $val;
    }

}